import data from "@assetsproj/pages.json";
export default {
  components: {},
  data() {
    return {
      count: 0,
      pageJson: data,
      appList: [
        // {
        //   title: "设备管理",
        //   icon: require("../../assets/images/mlgl.png"),
        //   type: "mlgl",
        //   route:"device"
        // },
        // {
        //   title: "字典维护",
        //   icon: require("../../assets/images/mlgl.png"),
        //   type: "dict",
        //   route:"dict"
        // },
      ],

      groupModal: false,
      title: "",
      apps: [],
      VIRTUAL_PATH: process.env.VUE_APP_VIRTUAL_PATH,
    };
  },
  computed: {
    user() {
      return this.$store.state.user;
    },
  },
  methods: {
    redirect(index) {
      var model = this.appList[index];
      const VIRTUAL_PATH = process.env.VUE_APP_VIRTUAL_PATH;
      this.$router.push(`${VIRTUAL_PATH}/${model.route}`);
    },
    menuClick(name) {
      if (name == "loginOut") {
        var that = this;
        this.$Modal.confirm({
          title: "退出",
          content: "确认退出当前账户么?",
          onOk: function () {
            localStorage.removeItem("token");
            that.$store.commit("clearUser");
            var VIRTUAL_PATH = process.env.VUE_APP_VIRTUAL_PATH;
            that.$router.push(`${VIRTUAL_PATH}/login`);
          },
        });
      }
    },
    getImage(icon) {
      return require("@/assets" + icon);
    },
    getApps() {
      this.appList = this.pageJson;
    },
    redirect(index) {
      var app = this.appList[index];
      // console.log(JSON.stringify(app));
      if (app.show == "alert") {
        this.groupModal = true;
        this.title = app.title;
        this.apps = app.menu;
        // this.children = app.menu;
        return;
      } else if (app.show == "linktoken") {
        const w = window.open("about:blank");
        w.location.href = `${app.path}?token=${localStorage.getItem("token")}`;
      } else if (app.show == "link") {
        this.$axios({
          baseURL: app.baseUrl,
          url: "account/loginUid",
          method: "POST",
          data: {
            uid: app.id,
          },
        })
          .then((res) => {
            if (res.code == 200) {
              var token = res.data.token;
              const w = window.open("about:blank");
              w.location.href = `${app.path}${token}`;
            } else {
              console.log(res.msg);
            }
          })
          .catch((e) => {
            console.log(e);
          });
      } else {
        let routerHref = this.$router.resolve(
          this.VIRTUAL_PATH + `${app.menu[0].children[0].path}?id=${app.id}`
        );
        window.open(routerHref.href);
      }
    },
    toTargetModal(item) {
      let address = this.$router.resolve(this.VIRTUAL_PATH + item.path);
      window.open(address.href);
    },
  },
  created() {
    this.$LoginAction.isLogin(this.user);
    this.getApps();
  },
};
